

#ifndef __DRIVER_CAN_OBSDATA_H
#define __DRIVER_CAN_OBSDATA_H

#include "HeaderFiles.h"

#define  CAN_ID_OBS_SEND_X0  0x0F1
#define  CAN_ID_OBS_SEND_X1  0x0F2

#define  CAN_ID_USERCTRL_REC_M1   0x0A1
#define  CAN_ID_USERCTRL_REC_M2   0x0B1

#define  CAN_ID_USERCTRL_TAR_M1   0x0C1
#define  CAN_ID_USERCTRL_TAR_M2   0x0D1


#define  CAN_ID_USERCTRL_TAR_MX   0x0CD



// user ctrl communication protocol matrix
typedef struct
{
    union
    {
        struct
        {
            uint16_t lifecnt      :8;

            uint16_t enable       :2;
            uint16_t precharge    :2;
            uint16_t reserve1     :4;

            uint16_t speedref_rpm :16;
            uint16_t accref_rpm_s :16;

            uint16_t reserve2     :8;
            uint16_t reserve3     :8;

        }bit;

        uint16_t data[4];

    }rec;


    union
    {
        struct
        {
            uint16_t lifecnt     :4;
            uint16_t FSM         :4;
            uint16_t is_rms_A    :8;
            uint16_t speedfb_rpm :16;

            uint16_t ctrlTemp    :8;
            uint16_t motorTemp   :8;
			uint16_t dcVol_V     :8;
            uint16_t batVol_V    :8;

        }bit;

        uint16_t data[4];

    }tar;

}STR_USER_CAN_CTRL;



typedef struct
{
    union 
    {
        
        uint16_t lifecnt     :4;
        uint16_t reserve1    :4;
        
        uint16_t dcVol_V     :8;
        uint16_t batVol_V    :8;
        
        uint16_t ctrlTemp_M1 :8;    
        uint16_t ctrlTemp_M2 :8;    
        
        uint16_t reserve2    :8;
        uint16_t reserve3    :8;
        uint16_t reserve4    :8;

    }bit;
    
    uint16_t data[4];

}STR_USER_CAN_STATE;


extern can_receive_message_struct  usercmd_message;      
extern can_trasnmit_message_struct canobs_message[2];  

extern void can_obsdata_init(void);
extern void can_obsdata_send(can_trasnmit_message_struct *transmit_message, int16_t *data);

extern void can_debugcmd_rec(can_receive_message_struct *receive_message);


#endif


